package by.amakarevich.services.impl;

import java.util.List;

import javax.inject.Inject;
import javax.persistence.metamodel.SingularAttribute;

import org.springframework.stereotype.Service;

import by.amakarevich.dataaccess.BookingDao;
import by.amakarevich.datamodel.Booking;
import by.amakarevich.datamodel.UserAccount;
import by.amakarevich.services.BookingService;

@Service
public class BookingServiceImpl  implements BookingService{
		@Inject
		private BookingDao bookingDao;
		
		@Override
		public void addNewBooking(Booking booking,  UserAccount userAccount) {
			booking.setUserAccount(userAccount);
			bookingDao.insert(booking);
		}

		@Override
		public Booking get(Long id) {
			return bookingDao.getById(id);
		}

		@Override
		public void updateBooking(Booking booking) {
			bookingDao.update(booking);
		}

		@Override
		public void deleteBooking(Long id) {
			bookingDao.delete(id);
		}
		  
		@Override
		    public void deleteAll() {
			bookingDao.deleteAll();
		}
		
		@Override
		public List<Booking> getAllBookingByUser(UserAccount userAccount, boolean payStatus, boolean canceled){
			return bookingDao.getAllBookingByUser(userAccount, payStatus,canceled);
		}

	    public List<Booking> getSortedAllBooking(SingularAttribute<Booking, ?> attr, boolean ascending, int startRecord, int pageSize){
	    	return bookingDao.getSortedAllBooking(attr, ascending, startRecord, pageSize);
	    }
	    
	    @Override
		public Long getCount() {
			return bookingDao.getCount();
		}
	    
	    @Override
	    public Booking getByBookingId(Long bookingId){
	    	return bookingDao.getByBookingId(bookingId);
	    }
}
